<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>空间分析服务-动态分段</title>

    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.css">
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>

<script type="text/javascript" src="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.js"></script>
<script type="text/javascript" src="../../dist/iclient9-leaflet.min.js"></script>
<script type="text/javascript">
    var map, generateSpatialDataService, generateSpatialDataParameters, resultLayer,
            themeService, themeParameters, themeLayer,
            baseUrl = "http://support.supermap.com.cn:8090/iserver/services/map-changchun/rest/maps/长春市区图",
            serviceUrl = "http://support.supermap.com.cn:8090/iserver/services/spatialanalyst-changchun/restjsr/spatialanalyst";
    map = L.map('map', {
        crs: L.supermap.NonEarthCRS({
            bounds: L.bounds([48.4, -7668.25], [8958.85, -55.58]),
            origin: L.point(48.4, -55.58)
        }),
        center: [-3861.911472192499, 4700],
        maxZoom: 18,
        zoom: 2
    });
    L.supermap.tiledMapLayer(baseUrl, {noWrap: true}).addTo(map).on("load", function () {
        generateSpatialDataAnalystProcess();
    });

    function generateSpatialDataAnalystProcess() {
        generateSpatialDataService = L.supermap.spatialAnalystService(serviceUrl);
        //配置动态分段Parameters
        generateSpatialDataParameters = new SuperMap.GenerateSpatialDataParameters({
            routeTable: "RouteDT_road@Changchun",
            routeIDField: "RouteID",
            eventTable: "LinearEventTabDT@Changchun",
            eventRouteIDField: "RouteID",
            measureField: "",
            measureStartField: "LineMeasureFrom",
            measureEndField: "LineMeasureTo",
            measureOffsetField: "",
            errorInfoField: "",
            dataReturnOption: new SuperMap.DataReturnOption({
                expectCount: 1000,
                dataset: "generateSpatialData@Changchun",
                deleteExistResultDataset: true,
                dataReturnMode: SuperMap.DataReturnMode.DATASET_ONLY
            })
        });
        generateSpatialDataService.generateSpatialData(generateSpatialDataParameters, function () {
            //用专题图展示分析结果
            showAnalysisResult_ThemeGridUnique();
        });
    }

    function showAnalysisResult_ThemeGridUnique() {
        //创建专题图服务实例
        themeService = L.supermap.themeService(baseUrl);
        //配置专题样式
        var style1, style2, style3;
        style1 = new SuperMap.ServerStyle({
            fillForeColor: new SuperMap.ServerColor(242, 48, 48),
            lineColor: new SuperMap.ServerColor(242, 48, 48),
            lineWidth: 1
        });
        style2 = new SuperMap.ServerStyle({
            fillForeColor: new SuperMap.ServerColor(255, 159, 25),
            lineColor: new SuperMap.ServerColor(255, 159, 25),
            lineWidth: 1
        });
        style3 = new SuperMap.ServerStyle({
            fillForeColor: new SuperMap.ServerColor(91, 195, 69),
            lineColor: new SuperMap.ServerColor(91, 195, 69),
            lineWidth: 1
        });
        //配置专题项
        var themeUniqueIteme1, themeUniqueIteme2, themeUniqueIteme3;
        themeUniqueIteme1 = new SuperMap.ThemeUniqueItem({
            unique: "拥挤",
            style: style1
        });
        themeUniqueIteme2 = new SuperMap.ThemeUniqueItem({
            unique: "缓行",
            style: style2
        });
        themeUniqueIteme3 = new SuperMap.ThemeUniqueItem({
            unique: "畅通",
            style: style3
        });
        var themeUnique = new SuperMap.ThemeUnique({
            uniqueExpression: "TrafficStatus",
            defaultStyle: new SuperMap.ServerStyle({
                fillForeColor: new SuperMap.ServerColor(48, 89, 14),
                lineColor: new SuperMap.ServerColor(48, 89, 14)
            }),
            items: [themeUniqueIteme1, themeUniqueIteme2, themeUniqueIteme3]
        });
        themeParameters = new SuperMap.ThemeParameters({
            themes: [themeUnique],
            datasetNames: ["generateSpatialData"],
            dataSourceNames: ["Changchun"]
        });
        themeService.getThemeInfo(themeParameters, function (serviceResult1) {
            var result = serviceResult1.result;
            if (result && result.newResourceID) {
                themeLayer = L.supermap.tiledMapLayer(baseUrl, {
                    noWrap: true,
                    cacheEnabled: false,
                    transparent: true,
                    layersID: result.newResourceID
                    //opacity: 0.8
                }).addTo(map);
            }
        });
    }
</script>
</body>
</html>